package cn.littlehx.myweb.controller;

import cn.littlehx.myweb.common.R;
import cn.littlehx.myweb.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserService userService;

    /**
     * 获取所有用户
     * @return
     */
    @GetMapping
    private R getAll(){
        List<cn.littlehx.myweb.domain.User> userList = userService.list();
        return new R(false, userList);
    }

    /**
     * 保存新用户
     * @param user
     * @return
     */
    @PostMapping
    private R create(@RequestBody cn.littlehx.myweb.domain.User user){
        Boolean save = userService.save(user);
        if(save){
            //保存成功
            return new R(true, null, "保存成功");
        }else {
            return new R(false, null, "保存失败, 已存在此email");
        }
    }
    @GetMapping("{email}")
    private R getUser(@PathVariable Integer email){
        return null;
    }


}
